package com.whl.sm.service.impl.expense;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.whl.sm.common.result.Result;
import com.whl.sm.mapper.expense.ExpenseTypeMapper;
import com.whl.sm.model.expense.ExpenseType;
import com.whl.sm.service.expense.ExpenseTypeService;
import com.whl.sm.service.system.OrgUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wuhaolun
 * @since 2021-10-18
 */
@Service
@Slf4j
public class ExpenseTypeServiceImpl extends ServiceImpl<ExpenseTypeMapper, ExpenseType> implements ExpenseTypeService {

    @Autowired
    private OrgUserService orgUserService;

    @Override
    public Result update(ExpenseType expenseType) {
        try{
            expenseType.setOperator(orgUserService.getCurrentUserId());
            if(expenseType.getId() == null){
                getBaseMapper().insert(expenseType);
            }
            else {
                getBaseMapper().updateById(expenseType);
            }
            return Result.ok();
        }catch (Exception e){
            log.error("[费用项管理]-------------->编辑费用项异常!");
            return Result.fail();
        }

    }
}
